﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;

/// <summary>
/// 是否在UI上
/// </summary>
public class IsClickInUI
{
    public static bool IsTouchedUI()
    {
        bool touchedUI = false;
        //TODO 移动端
        if (Application.isMobilePlatform)
        {
            if (Input.touchCount > 0 && EventSystem.current.IsPointerOverGameObject(Input.GetTouch(0).fingerId))
            {
                touchedUI = true;
            }
        }
        //TODO PC端
        else if (EventSystem.current.IsPointerOverGameObject())
        {
            touchedUI = true;
        }
        return touchedUI;
    }

    public static bool IsTouchedUI(UnityEngine.EventSystems.EventSystem sys)
    {
        bool touchedUI = false;
        //TODO 移动端
        if (Application.isMobilePlatform)
        {
            if (Input.touchCount > 0 && sys.IsPointerOverGameObject(Input.GetTouch(0).fingerId))
            {
                touchedUI = true;
            }
        }
        //TODO PC端
        else if (sys.IsPointerOverGameObject())
        {
            touchedUI = true;
        }
        return touchedUI;
    }

    public static bool IsTouchedUI(UnityEngine.EventSystems.EventSystem sys, UnityEngine.UI.GraphicRaycaster caster)
    {
        PointerEventData data = new PointerEventData(sys);
        data.position = Input.mousePosition;
        List<RaycastResult> results = new List<RaycastResult>();
        caster.Raycast(data, results);
        if (results.Count > 0)
            return true;
        else
            return false;
    }

}
